#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
    int year = 0;
    int month = 0;
    int days[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
    while (scanf("%d %d", &year, &month) == 2)
    //while(scanf("%d %d",&year,&month)!=EOF)
    //while(~scanf("%d %d",&year,&month))//EOF是-1，进行取反，二进制变成全0
    {
        int day = days[month - 1];//用数组将每月多少天存下来
        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
        {
            if (month == 2)
            {
                day = day + 1;//闰年二月多一天
            }
        }
        printf("%d\n", day);
    }
    return 0;
}